package com.xucy.springboot.designmodel.structural.composite;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author xucy
 * @Date 2019-07-19 14:00
 * @Description 课程目录，可实现 添加 删除 获得名称 打印
 **/

public class CourseCatalog extends CourseComponent {

    List<CourseComponent> courseComponents=new ArrayList<>();

    private String name;

    private  int level;
    public CourseCatalog(String name,int level) {
        this.name = name;
        this.level=level;
    }

    @Override
    public void add(CourseComponent courseComponent) {
        courseComponents.add(courseComponent);
    }

    @Override
    public void remove(CourseComponent courseComponent) {
        courseComponents.remove(courseComponent);
    }

    @Override
    public String getName(CourseComponent courseComponent) {
        return this.name;
    }

    @Override
    public void print() {
        System.out.println("目录名："+this.name);
        for(int i=0;i<courseComponents.size();i++){
            if(level!=0){
                for(int j=0;j<level;j++){
                    System.out.print("  ");
                }

            }
            CourseComponent courseComponent=courseComponents.get(i);
            courseComponent.print();
        }
    }
}
